const db = require("../../db/mysql");

const logError = (err, ctx) => {
    const { code, message } = err;
    const { method, url, header } = ctx.request;
    // 存入log_error表
    db.query('INSERT INTO log_error (code, message, method, url, header) VALUES (?, ?, ?, ?, ?)', [code, message, method, url, JSON.stringify(header)]);
  ctx.app.emit('error', err, ctx);
  ctx.body = {
    code,
    message,   
    error: err
  }
}


module.exports = {addError};